package com.wc.AlgoOJ_train.train3_算法大礼包.c1_广度优先搜索.AG0203_马的移动;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/1/25 22:31
 * @description http://43.138.190.70:8888/p/AG0203
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int[] posX = new int[]{-2, -1, -2, 1, 2, -1, 2, 1};
    static int[] posY = new int[]{-1, -2, 1, -2, -1, 2, 1, 2};
    static String s1, s2;
    static int x1, y1, x2, y2;
    static int[] map = new int[128];
    static int N = 10;
    static int[][] grip = new int[N][N];

    public static void main(String[] args) {
        for (int i = 'a', j = 1; i <= 'h'; i++, j++) {
            map[i] = j;
        }
        while (sc.hasNext()) {
            s1 = sc.next();
            s2 = sc.next();
            x1 = s1.charAt(1) - '0';
            y1 = map[s1.charAt(0)];
            x2 = s2.charAt(1) - '0';
            y2 = map[s2.charAt(0)];
            init();
            out.printf("To get from %s to %s takes %d knight moves.\n", s1, s2, bfs(x1, y1));
            out.flush();
        }
    }

    static void init() {
        for (int i = 0; i < N; i++) {
            Arrays.fill(grip[i], 0);
        }
    }

    static int bfs(int x, int y) {
        Queue<Integer> q = new LinkedList<>();
        q.add(x);
        q.add(y);
        while (true) {
            x = q.poll();
            y = q.poll();
            if (x == x2 && y == y2) {
                return grip[x][y];
            }
            for (int i = 0; i < 8; i++) {
                int nx = x + posX[i];
                int ny = y + posY[i];
                if (!isBorder(nx, ny) && grip[nx][ny] == 0) {
                    grip[nx][ny] = grip[x][y] + 1;
                    q.add(nx);
                    q.add(ny);
                }
            }
        }
    }

    static boolean isBorder(int x, int y) {
        return x < 1 || x > 8 || y < 1 || y > 8;
    }

}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
